package com.cas.webservice.model;

import java.util.ArrayList;
import java.util.List;

import com.cas.object.Upload_Sale_Commond;
import com.cas.scalls.util.HttpUtil;
import com.cas.scalls.util.ObjectData;
import com.cas.scalls.util.TCPClient;

public class ThreadControlR extends Thread{
	String ipaddr;
	int port;
	List<byte[]> data;
	List<ObjectData> listobjects;
	public ThreadControlR(String ipaddr, int port, List<byte[]> data) {
		this.ipaddr = ipaddr;
		this.port = port;
		this.data = data;
		listobjects = new ArrayList<ObjectData>();
	}
	@Override
	public void run() { 
		try {
			ObjectData objrecive = new ObjectData(ipaddr);
			objrecive.listbyte = TCPClient.cmdForScale(ipaddr, port, data);
			listobjects.add(objrecive);
			savedatafromscale(listobjects);
		} catch (Exception e) {
		
		}
    } 
	public static boolean savedatafromscale(List<ObjectData> listobjects) throws Exception{
		for(ObjectData obj:listobjects){
			Upload_Sale_Commond.saveInfoAndUpdate(obj.listbyte, obj.ipaddr);	
		}
		for(ObjectData obj:listobjects){
			HttpUtil.doPost("127.0.0.1", Upload_Sale_Commond.makeCommndToPc(obj.listbyte, obj.ipaddr), "uploadTranInfo");	
		}
		return true;
	}
}
